/**
 * 子弹基类
 */
var BaseNode = require('./../../../../FrameWork/Component/BaseNode');
var _ = require('./../../../../FrameWork/we_underscore');
cc.Class(
{
    extends: BaseNode,

    onLoad()
    {
        this.node.x = -cc.winSize.width;
        this.node.y = -cc.winSize.height
    },

    start()
    {
        // this.node.x = _.random(cc.winSize.width * 0.1, cc.winSize.width * 0.9) - cc.winSize.width * 0.45;
        // this.node.y = cc.winSize.height * 0.5 + this.getHeight() * 0.5; 
        var space = this.getTag() % 2 == 1 ? 1 : -1;
        this.node.x = -cc.winSize.width * 0.5 * space;
        this.node.y = cc.winSize.height * 0.5
        var bezier = [
            cc.v2(-cc.winSize.width * 0.5 * space, cc.winSize.height * 0.5),
            cc.v2(0, 0),
            cc.v2(-cc.winSize.width * 0.5 * space, -cc.winSize.height * 0.5),
        ];
        var bezierForward = cc.bezierTo(10, bezier);

        var actArray = [bezierForward,
            cc.callFunc(function()
            {
                this.node.destroy();
            }.bind(this))
        ];
        var seq = cc.sequence(actArray);
        this.node.runAction(seq);
        // this.node.runAction(cc.moveBy(7, cc.v2(0, -(cc.winSize.height + this.getHeight()))));
    },

    update(dt)
    {
        if (null == this.lastP)
        {
            this.lastP = cc.v2(this.node.x, this.node.y);
            return;
        }
        var currentP = cc.v2(this.node.x, this.node.y);

        var deltaP = currentP.sub(this.lastP)
        var angle = deltaP.signAngle(cc.v2(0, 1));
        this.node.rotation = angle * (180 / Math.PI) + 180;
    }
});